package com.coincalf.web;


import com.baomidou.mybatisplus.plugins.Page;
import com.coincalf.entity.AccountDetail;
import com.coincalf.framework.enums.BusinessType;
import com.coincalf.framework.http.Response;
import com.coincalf.service.AccountDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/accountDetail")
@Api(value = "资金流水", description = "资金流水")
public class AccountDetailController {

    @Autowired
    private AccountDetailService accountDetailService;
    @Autowired
    private CommonController commonController;


    @GetMapping("list")
    @ApiOperation(value = "资金流水纪录", notes = "资金流水纪录", httpMethod = "GET")
    public Response list(HttpServletRequest request,
                         @RequestParam(required = false) String businessType,
                         @RequestParam(required = false) Long coinId,
                         @RequestParam(required = false) Integer current,
                         @RequestParam(required = false) Integer size) {
        Long userId = commonController.getUserId(request);
        if (current == null || current < 1) {
            current = 1;
        }
        if (size == null || size < 1) {
            size = 10;
        }
        Page<AccountDetail> page = new Page<>();
        page.setCurrent(current).setSize(size);
        Page<AccountDetail> list = accountDetailService.queryList(businessType, userId, coinId, page);
        list.getRecords().forEach(x -> {
            x.setRefAccountId(null);
            x.setUserId(null);
            x.setAccountId(null);
            x.setOrderId(null);
            x.setRemark(null);
            x.setBusinessType(BusinessType.getDescByCode(x.getBusinessType()));
        });
        return Response.ok(list);
    }

}
